package com.example.barcodeapp.ui.home;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import com.example.barcodeapp.R;
import com.example.barcodeapp.ui.LoginActivity;

public class AdapterRili extends RecyclerView.Adapter<AdapterRili.ViewHolder> {
    private Context context;


    public AdapterRili(Context context) {
        this.context = context;
    }

    private IClick callback;

    public void setClick(IClick cb) {
        callback = cb;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_rili, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //取消点击
        holder.riliQuxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent intent = new Intent(context, LoginActivity.class);
//                context.startActivity(intent);

                if (holder.riliQuxiao.getText().toString().equals("取消")){
                    new AlertDialog.Builder(context).setTitle("确定取消预约吗")
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //点击确定触发的事件
                                    holder.riliQuxiao.setText("预约");
                                }
                            })
                            .setNegativeButton("返回", new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    //点击取消触发的事件

                                }
                            }).show();

                }else {
                }


            }
        });



        //条目点击
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 6;
    }



    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView riliTouxiang;
        private TextView textView40;
        private TextView textView41;
        private TextView textView43;
        private TextView textView42;
        private Button riliQuxiao;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            riliTouxiang = (ImageView) itemView.findViewById(R.id.rili_touxiang);
            textView40 = (TextView) itemView.findViewById(R.id.textView40);
            textView41 = (TextView) itemView.findViewById(R.id.textView41);
            textView43 = (TextView) itemView.findViewById(R.id.textView43);
            textView42 = (TextView) itemView.findViewById(R.id.textView42);
            riliQuxiao = (Button) itemView.findViewById(R.id.rili_quxiao);
        }
    }

    public interface IClick {

        void click(int pos);

    }
}
